import request from "@/utils/request";
import type { GetSpuListParams, GetSpuListResponse } from "./model/spuModel";
import type {
  BaseSaleAttrList,
  AllSpuItem,
  AllSpuImageList,
  AllSpuSaleAttrList,
} from "./model/spuModel";

enum Api {
  getSpuListUrl = "/admin/product",
  getBaseSaleAttrListUrl = "/admin/product/baseSaleAttrList",
  addSpuUrl = "/admin/product/saveSpuInfo",
  updateSpuUrl = "/admin/product/updateSpuInfo",
  getSpuImageListUrl = "/admin/product/spuImageList",
  getSpuSaleAttrListUrl = "/admin/product/spuSaleAttrList",
  deleteSpuUrl = "/admin/product/deleteSpu",
}

export const getSpuListApi = ({
  page,
  limit,
  category3Id,
}: GetSpuListParams) => {
  return request.get<any, GetSpuListResponse>(
    Api.getSpuListUrl + `/${page}/${limit}`,
    {
      params: { category3Id },
    }
  );
};

export const getBaseSaleAttrListApi = () => {
  return request.get<any, BaseSaleAttrList>(Api.getBaseSaleAttrListUrl);
};

export const addSpuApi = (data: AllSpuItem) => {
  return request.post<any, null>(Api.addSpuUrl, data);
};

export const updateSpuApi = (data: AllSpuItem) => {
  return request.post<any, null>(Api.updateSpuUrl, data);
};

export const getSpuImageListApi = (id: number) => {
  return request.get<any, AllSpuImageList>(Api.getSpuImageListUrl + `/${id}`);
};

export const getSpuSaleAttrListApi = (id: number) => {
  return request.get<any, AllSpuSaleAttrList>(
    Api.getSpuSaleAttrListUrl + `/${id}`
  );
};

export const deleteSpuApi = (id: number) => {
  return request.delete<any, null>(Api.deleteSpuUrl + `/${id}`);
};
